﻿using UnityEditor;
using UnityEditor.Callbacks;
namespace NodeEditor
{
    public class NodeEditorUtility
    {
        [OnOpenAsset(1)]
        public static bool Open(int id, int line)
        {
            var assetPath = AssetDatabase.GetAssetPath(id);
            var tree = AssetDatabase.LoadAssetAtPath<Tree>(assetPath);
            if (tree == null)
                return false;

            var window = EditorWindow.GetWindow<NodeEditor>();
            window.titleContent = new UnityEngine.GUIContent("节点编辑器");
           
            window.nodeView.UpdateTree(tree);
            if (tree.root == null)
            {
                tree.root =  window.nodeView.CreateNode(typeof(Root)).node as Root;
            }

            return true;
        }
    }
}
